package com.mingqijia.gassafety.gateway.controller.openapi;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.webserver.request.openapi.order.OpenOrderCompleteRequest;
import com.mingqijia.gassafety.webserver.service.EquipmentService;
import com.mingqijia.gassafety.webserver.service.open.OpenOrderService;
import com.towngas.open.servicecommon.annotation.Open;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author zhangfei
 * @version 1.0.0
 * @ClassName EquipmentController.java
 * @Description 走开放平台
 * @createTime 2022年11月17日
 */

@RestController
@Api(tags = "开放平台相关")
@RequestMapping("/console/v1/openapi/workorder/")
public class OpenApiController {

    @Autowired
    private EquipmentService equipmentService;

    @Autowired
    OpenOrderService openOrderService;

    @ApiOperation( value = "检验设备存不存在")
    @GetMapping(value = "/equipment/checkEquipment",name = "检验设备存不存在")
    @Open(
            value = "checkEquipment",//接口名称 中英文+.组成 必填
            version = "1.0",//接口版本号 必填
            ignoreValidate = false,//是否忽略签名验证，默认：false，如果接口本来已经有签名验证可以设置为false来忽略开放平台的签名验证
            permission = false //是否需要开放平台授权 默认：true
    )
    public CommonResponse<Object> checkEquipment(@RequestParam("imei") String imei){
        return CommonResponse.success( equipmentService.checkEquipment(imei) );
    }

    @ApiOperation( value = "工单信息同步")
    @RequestMapping(value = "/orderComplete", method = RequestMethod.POST, name = "工单信息同步")
    @Open(
            value = "orderComplete",//接口名称 中英文+.组成 必填
            version = "1.0",//接口版本号 必填
            ignoreValidate = false,//是否忽略签名验证，默认：false，如果接口本来已经有签名验证可以设置为false来忽略开放平台的签名验证
            permission = true //是否需要开放平台授权 默认：true
    )
    public CommonResponse<Object> orderComplete(@RequestBody @Valid OpenOrderCompleteRequest request){
        openOrderService.orderComplete(request);
        return CommonResponse.success("success");
    }
}